/*
 * RulesManager.h
 *
 *  Created on: Dec 18, 2013
 *      Author: artech
 */

#ifndef RULESMANAGER_H_
#define RULESMANAGER_H_

#include "model/GridModel.h"
#include "model/SquareModel.h"

#include <QList>
#include <QMap>
#include <QPair>
#include <QStack>

class RulesManager
{
public:
   RulesManager();
   virtual ~RulesManager();

   void initialize(QMap<QPair<quint8, quint8>, quint8> grid);

   void applyRules();

private:
   GridModel _gridModel;
   QStack<SquareModel*> _squareToTreatStack;
   QVector<QVector<QSet<SquareModel*> > > _histogramValueForLine;
   QVector<QVector<QSet<SquareModel*> > > _histogramValueForColumn;
   QVector<QVector<QSet<SquareModel*> > > _histogramValueForSquare9;

   void treatLine(SquareModel* squareModel);
   void treatColumn(SquareModel* squareModel);
   void treatSquare9(SquareModel* squareModel);

   void treatPivotLine(SquareModel* squareModel);
   void treatPivotColumn(SquareModel* squareModel);

   void treatSquare(quint8 lineNb, quint8 columnNb, quint8 value);

   void treatOnlyOneInLine(SquareModel* squareModel, quint8 value);
   void treatOnlyOneInColumn(SquareModel* squareModel, quint8 value);
   void treatOnlyOneInSquare9(SquareModel* squareModel, quint8 value);

   void treatOnlyOne(SquareModel* squareModel, quint8 value);

   void printGrid();
   void clear();
};

#endif /* RULESMANAGER_H_ */
